package com.ziyun.erp.web.modules.order.controller;

import com.ziyun.erp.modules.order.entity.OrderRemarksEntity;
import com.ziyun.erp.modules.order.vo.OrderRemarksVo;
import com.ziyun.erp.modules.order.service.OrderRemarksService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 订单备注表
 *
 * @author gaosheng
 * @email 
 * @date 2018-08-06 10:47:31
 */
@RestController
@RequestMapping("order/orderremarks")
public class OrderRemarksController {
    @Autowired
    private OrderRemarksService orderRemarksService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("order:orderremarks:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = orderRemarksService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{orId}")
    @RequiresPermissions("order:orderremarks:info")
    public R info(@PathVariable("orId") Integer orId){
        OrderRemarksEntity orderRemarks = orderRemarksService.selectById(orId);

        return R.ok().put("orderRemarks", orderRemarks);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("order:orderremarks:save")
    public R save(@RequestBody OrderRemarksEntity orderRemarks){
        orderRemarksService.insert(orderRemarks);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("order:orderremarks:update")
    public R update(@RequestBody OrderRemarksEntity orderRemarks){
        ValidatorUtils.validateEntity(orderRemarks);
        orderRemarksService.updateAllColumnById(orderRemarks);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("order:orderremarks:delete")
    public R delete(@RequestBody Integer[] orIds){
        orderRemarksService.deleteBatchIds(Arrays.asList(orIds));

        return R.ok();
    }

    /**
     * 查询订单备注
     */
    @RequestMapping("/orderlist/{orderId}")
    public R orderlist(@PathVariable("orderId") String orderId){
        Map<String, Object> param = new HashMap<>(1);
        param.put("orderId", orderId);
        List<OrderRemarksVo> orderRemarksVos = orderRemarksService.selectOrderRemarksVosByMap(param);

        return R.ok().put("orderRemarks", orderRemarksVos);
    }


}
